<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList, java.util.Iterator" %>
<%@ page import="util.Helper,pojo.UserAttr" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户列表</title>
<link rel="stylesheet" href="../css/base.css" />
</head>
<body>
    <div class="wrap">
        <div class="header">
            <p class="tool_bar">
                <a href="javascript:location.reload();">[刷新]</a>
                <a href="javascript:history.go(-1);">&lt;&lt;返回上一页</a>
                <a href="../index">返回主页&gt;&gt;</a>
                <a href="../logout">[退出]</a>
            </p>
            <h1>管理菜单——用户列表</h1>
        </div>
        <div class="content">
            <div class="poll_users">
                <%
                   Object obj   = request.getAttribute("users");
                   if(obj == null) {
                       out.print("还没用户！<a href=\"../index\">添加用户</a>");
                   } else {
                 %>
                 <form action="./poll" method="POST" name="poll_form">
                 <table cellspacing="1" cellpadding="1" border="1" width="700" align="center">
                 <tr>
                    <td colspan="6" style="text-align: center;">投票项目列表<sub>[<a href="../index">添加新项</a>]</sub></td>
                 </tr>
                 <tr>
                    <td width="10%">用户ID</td>
                    <td width="20%">用户名</td>
                    <td width="10%">用户类型</td>
                    <td width="20%">邮箱</td>
                    <td width="20%">创建时间</td>
                    <td>操作</td>
                </tr>
                 <%
                       ArrayList<UserAttr> users  = (ArrayList<UserAttr>)obj;
                       Iterator<UserAttr> iUsers  = users.iterator();
                       while(iUsers.hasNext()) {
                           UserAttr user    = (UserAttr)iUsers.next();
                           int userId       = user.getUserId();
                           String userName  = user.getUserName();
                           int userType     = user.getUserType();
                           String userEmail = user.getUserEmail();
                           String createTime = user.getCreateTime();
                           String typeName  = "普通会员";
                           if(userType == 1) {
                               typeName  = "管理员";
                           }
                %>
                <tr>
                    <td><%=userId %></td>
                    <td><%=userName %></td>
                    <td><%=typeName %></td>
                    <td><%=userEmail %></td>
                    <td><%=createTime %></td>
                    <td><a href="./deluser?id=<%=userId%>">删除</a></td>
                </tr>
                <% 
                       }
                       out.print("</table>");
                   }
                %>
            </div>
        </div>
        <jsp:include page="../comm/footer.jsp" flush="true"/>
    </div>
</body>
</html>